<template>
	<div class="select4Wrap">
		<div class="select4Box">
			<div class="fixedBarBtn" @click="clikcDesc('wytw')">我要提问</div>
			<div class="imgBanner" v-if="totlanum>10" @click="clikcDesc1"></div>

			<div class="adToperBox">
				<div class="adToper flex-h">
					<span class="flex1 sp1">
						<img class="imgIcon" src="~/static/iconsvgs/college_icon_roll.png" alt="">
						<b>看大家问了啥</b>
					</span>

				</div>
			</div>
			<div v-show="wdLens>0" style="min-height: 5rem;">
				<question-answer :quesData="wdData" v-on:listToRewd='listFromPare'></question-answer>
			</div>
			<div v-show="wdLens===0">
				<img style="display: block;width: 3.5rem;height: 3.65rem;margin: 0.5rem auto 0.2rem;" src="~/static/icon/blank.png"
				 alt="">
				<span style="display: block;text-align: center;font-size: 0.3rem;">暂无数据</span>
				<div style="height: 1rem;"></div>
			</div>



		</div>

		<select-desc :showWho='whos' :wdDetail='wdDetails' v-on:clearShowDesc="clearDesc" :showselect2='showsdesc'
		 v-on:listToChid='showMsgFormChid' :reData='remeData' :remTitle="remTitles" :authorData="authorDatas"></select-desc>
		<wenda-list ref='aas' :bottomCounts='boteNum' v-on:clearShowDesc="clearDesc1" :showselect3='showsdesc1'>

		</wenda-list>
	</div>
</template>

<script>
	import { getCommonAnser } from "~/api/college";
	import { getAnswerService, geQuestionAnswer } from '~/api/school'
	import selectDesc from '~/components/selectNews2'
	import wendaList from '~/components/selectNews4'
	import questionAnswer from '~/components/questionAnswer'

	import ls from 'store2';
	export default {
		props: {

		},
		components: {
			selectDesc,
			questionAnswer,
			wendaList

		},
		data() {
			return {
				showsdesc: false,
				showsdesc1: false,
				whos: '',
				wdDetails: '',
				wdNum: 1,
				wdData: [],
				remeData: [],
				remTitles: '',
				authorDatas: {},
				wdLens: 1,
				boteNum: 1,
				totlanum: 0
			};
		},
		created() {
			this.showUnivWd()
		},
		computed: {

		},
		mounted: function() {

			this.showCommonWd()
		},
		methods: {
			isTerminal() {
				var u = navigator.userAgent;
				var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
				var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
				if (isAndroid) {
					return "isAndroid"
				} else if (isiOS) {
					return "isiOS"
				}
			},
			showAnBack() {
				if (this.isTerminal() == 'isAndroid') {
					if (window.history && window.history.pushState) {
						history.pushState(null, null, document.URL);
						window.addEventListener('popstate', this.fun, false); //false阻止默认事件
					}
				}

			},
			fun() {
				this.showsdesc = false
				this.showsdesc1 = false
				setTimeout(() => {
					this.removeback()
				}, 50)

			},
			removeback() {
				window.removeEventListener('popstate', this.fun, false);
				setTimeout(()=>{
					this.commonJs.android()
				},10)
			},
			listFromPare(data) {

				this.$vux.loading.show();
				this.whos = "rmwd"
				this.remTitles = data.title
				let obj = {
					"title": data.title,
					"createTime": data.createTime,
					"avatar": data.author.avatar,
					"name": data.author.name,
					"status": data.status,
					"answerCount": data.answer_count,

				}
				this.authorDatas = obj
				getAnswerService(data.questionId).then(res => {
					if (res.data) {
						this.remeData = res.data
					}
					this.$vux.loading.hide();
				}).catch((error) => {
					this.$vux.toast.text('暂无数据');
					this.$vux.loading.hide();
				})

				// setTimeout(() => {
				this.showsdesc = true
				this.commonJs.destr()
				setTimeout(() => {
					this.showAnBack();
				}, 10)
				// }, 50)
			},
			showMsgFormChid(data) {
				if (data === 'tjcg') {
					setTimeout(() => {
						this.showsdesc = false
						this.showUnivWd()
					}, 500)
				}
			},
			clearDesc() {
				this.showsdesc = false
				this.removeback()
			},
			clearDesc1() {
				this.showsdesc1 = false

				this.removeback()
			},
			showUnivWd() {
				this.$vux.loading.show()
				geQuestionAnswer({
					"academyCode": ls.get('applsData').academyCode + "",
					"page": '1',
					"limit": 10

				}, true).then(res => {
					this.wdData = res.data;
					this.wdLens = res.data.length;
					this.totlanum = res.meta.total;
					this.$vux.loading.hide()
				}).catch((error) => {
					this.$vux.loading.hide()
					this.wdLens = 0
				})
			},
			showCommonWd() {
		
				getCommonAnser({
					"academyCode": ls.get('applsData').academyCode + ""
				}, true).then(res => {
					if (res.code === '0') {
						if (res.data) {
							this.wdDetails = res.data;
							this.wdDetails ? this.wdNum = 2 : this.wdNum = 1

						}
						// this.$vux.loading.hide();
					}

					// this.$vux.loading.hide()
				}).catch((error) => {
					// this.$vux.loading.hide()	
					// this.$vux.loading.hide();
				})
			},
			clikcDesc(sre) {
				// 				this.$vux.loading.show({
				// 					text: '正在加载'
				// 				})
				this.whos = sre
				this.showsdesc = true;
				this.showCommonWd()
				this.commonJs.destr()
				setTimeout(() => {
					this.showAnBack();
				}, 10)
			},
			clikcDesc1() {
				this.showsdesc1 = true;
				this.boteNum = 1;
				console.log(111111000000)
				this.$refs.aas.showWdList();
				this.commonJs.destr()
				setTimeout(() => {
					this.showAnBack();
				}, 10)
			}


		}
	};
</script>


<style scoped lang="less">
	.select4Wrap {
		width: 7.5rem;
		height: auto;
		background: #fff;
		padding: 0.2rem 0;

		.fixedBarBtn {
			width: 6.9rem;
			height: 0.8rem;
			background: rgba(255, 255, 255, 1);
			border-radius: 0.1rem;
			border: 1px solid rgba(104, 189, 26, 1);
			font-size: 0.3rem;
			margin: 0 auto;
			font-weight: bold;
			color: rgba(108, 191, 32, 1);
			line-height: 0.8rem;
			text-align: center;
		}

		.imgBanner {
			margin: 0.4rem auto 0.1rem;
			overflow: hidden;
			width: 6.9rem;
			height: 2rem;
			background: url('~/static/wdbj.png') no-repeat;
			background-size: 100% 100%;
			border-radius: 0.1rem;
		}

		.adToperBox {
			width: 6.9rem;
			margin: 0 auto;
			height: 0.9rem;


			.sp1,
			.sp2 {
				font-size: 0.28rem;
				line-height: 0.9rem;

				b {
					font-size: 0.34rem;
					font-weight: bold;
					color: rgba(34, 34, 34, 1);
					vertical-align: middle;
					margin-left: 0.1rem;
				}

				.imgIcon {
					width: 0.24rem;
					height: 0.24rem;
					vertical-align: middle;

				}
			}

			.sp1 {
				text-align: left;
			}

			.sp2 {



				.imgIcon {
					vertical-align: middle;
					width: 0.4rem;
					height: 0.4rem;
				}


			}

		}


	}
</style>
